{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 第二章习题\n",
    "\n",
    "### 一、填空题\n",
    "\n",
    "1.列表的`sort()`方法没有返回值,或者说返回值为__none______."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.已知列表 `data=[1,2,30 4]`，那么`data[2:100]`的值为____30,4____."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.己知`x=3`和`y=5`,那么执行语句`x,y=y,x`之后，`y`的值为_3_______."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．已知字典 `data= {'a;97, 'A' :65}`,那么`data.get('a', None)`的值为___97_____."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 二、判断题\n",
    "\n",
    "1.生成器表达式的计算结果是一个元组。`(  F  )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2．包含列表的元组可以作为字典的“键”。`(  F  )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3．包含列表的元组不可以作为集合的元素。`(   T )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．列表的`rindex()`方法返回指定元素在列表中最后一次出现的位置。`(  T  )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 三、编程题\n",
    "\n",
    "1.输入一个字符串，输出其中每个字符的出现次数。要求使用标准库`collotections`中的`Counter`类,请自行查阅相关用法。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入字符串1235678\n",
      "Counter({'1': 1, '2': 1, '3': 1, '5': 1, '6': 1, '7': 1, '8': 1})\n"
     ]
    }
   ],
   "source": [
    "from collections import Counter\n",
    "a = input(\"请输入字符串\")\n",
    "b = Counter(a)\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2．输入一个字符串,输出其中只出现了一次的字符及其下标。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串：1285345436\n"
     ]
    }
   ],
   "source": [
    "text = input('请输入一个字符串：')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('1', 0), ('2', 1), ('8', 2), ('6', 9)]\n"
     ]
    }
   ],
   "source": [
    "positions = [(ch, index) for index, ch in enumerate(text) if text.index(ch)==text.rindex(ch)]\n",
    "print(positions)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3．输入一个字符串,输出其中每个唯一字符最后一次出现的下标。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串：724365641\n"
     ]
    }
   ],
   "source": [
    "text = input('请输入一个字符串：')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('7', 0), ('2', 1), ('3', 3), ('5', 5), ('6', 6), ('4', 7), ('1', 8)]\n"
     ]
    }
   ],
   "source": [
    "positions =[(ch,index) for index,ch in enumerate(text)\n",
    "if index == text.rindex(ch)]\n",
    "print(positions)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．输入包含若干集合的列表，输出这些集合的并集。提示:使用`reduce()`函数和`operator`模块中的运算实现多个集合的并集。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入包含若干集合的列表：[{34,34},{32,65}]\n"
     ]
    }
   ],
   "source": [
    "from functools import reduce\n",
    "from operator import __or__\n",
    "x = eval(input('请输入包含若干集合的列表：'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{32, 65, 34}\n"
     ]
    }
   ],
   "source": [
    "print(reduce(__or__,x))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5．输入一个字符串,检查该字符串是否为回文（正着读和反看读都一样的字符串)，如果是就输出`Yes`，否则输出`No`。要求使用切片实现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串23432\n",
      "Yes\n"
     ]
    }
   ],
   "source": [
    "alist1 = input('请输入一个字符串')\n",
    "\n",
    "alist2 =alist1[::-1]\n",
    "if alist1 == alist2:\n",
    "    print('Yes')\n",
    "else:\n",
    "    print('No')\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 课本上65页课后习题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.()里的值\n",
    "\n",
    "2.4\n",
    "\n",
    "3.None\n",
    "\n",
    "4.remove()\n",
    "\n",
    "5.[6,7,9,11]\n",
    "\n",
    "6.{},键和值，键\n",
    "\n",
    "7.items(),keys(),values()\n",
    "\n",
    "8.[\"dict(zip(a,b))\"]\n",
    "9.b=a[::3]\n",
    "10.5 for i in range(10)\n",
    "\n",
    "11.不可以"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = ['789546123','asdfgh','693741852']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['789546123', 'asdfgh', '693741852']\n"
     ]
    }
   ],
   "source": [
    "print(list(filter(lambda s:len(set(s))/len(s) >0.5,data)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]\n"
     ]
    }
   ],
   "source": [
    "def prime(x):                       \n",
    "    for i in range(2,x):\n",
    "        if x%i==0:\n",
    "            return False\n",
    "        if i==x-1:\n",
    "            return True\n",
    "output=filter(prime,range(2,1001))\n",
    "print(list(output))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "14,为了不破坏原本列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[10, 81, 59, 88, 20, 33, 45, 21, 38, 85, 80, 35, 10, 14, 51, 37, 16, 39, 65, 95, 4, 14, 51, 68, 73, 42, 33, 17, 55, 38, 96, 66, 52, 35, 23, 61, 32, 81, 46, 33, 58, 51, 31, 47, 71, 35, 23, 8, 59, 5, 1, 94, 62, 36, 97, 81, 96, 4, 20, 17, 94, 62, 54, 70, 62, 20, 8, 8, 85, 95, 33, 44, 76, 67, 34, 83, 65, 79, 30, 75, 99, 57, 96, 16, 30, 47, 39, 77, 97, 0, 54, 25, 8, 21, 74, 38, 16, 6, 6, 60, 71, 60, 23, 25, 32, 55, 60, 100, 1, 71, 6, 55, 42, 3, 84, 6, 71, 45, 9, 17, 35, 70, 56, 96, 42, 82, 83, 2, 23, 50, 18, 63, 100, 87, 73, 54, 80, 17, 29, 14, 77, 30, 33, 46, 43, 88, 40, 96, 8, 80, 69, 73, 56, 50, 100, 10, 27, 30, 45, 99, 21, 60, 60, 28, 31, 5, 37, 46, 39, 71, 30, 88, 87, 46, 52, 12, 87, 49, 18, 88, 83, 82, 65, 42, 65, 14, 48, 54, 43, 41, 40, 93, 84, 10, 21, 60, 52, 41, 99, 16, 22, 26, 12, 72, 96, 46, 59, 89, 7, 45, 80, 50, 90, 60, 21, 30, 28, 50, 36, 85, 32, 80, 63, 43, 46, 29, 73, 64, 59, 49, 78, 14, 51, 79, 88, 25, 56, 72, 37, 20, 13, 95, 13, 81, 94, 97, 59, 75, 57, 91, 6, 83, 9, 5, 28, 91, 19, 10, 99, 85, 51, 37, 24, 11, 88, 83, 47, 46, 14, 65, 54, 23, 49, 52, 70, 75, 74, 3, 50, 34, 65, 40, 83, 90, 92, 77, 97, 78, 15, 0, 28, 10, 83, 72, 96, 69, 15, 78, 65, 37, 23, 66, 33, 99, 58, 98, 17, 96, 19, 93, 7, 32, 33, 90, 92, 5, 34, 11, 89, 22, 45, 80, 6, 18, 100, 7, 99, 13, 37, 82, 77, 70, 22, 72, 88, 67, 83, 14, 72, 36, 78, 14, 67, 47, 27, 78, 46, 8, 27, 77, 85, 71, 96, 38, 35, 44, 63, 96, 54, 4, 13, 75, 0, 40, 91, 37, 36, 38, 59, 24, 69, 59, 59, 4, 77, 15, 85, 59, 49, 40, 93, 70, 30, 44, 48, 33, 6, 40, 34, 7, 25, 46, 68, 79, 51, 50, 22, 81, 39, 87, 1, 92, 21, 83, 67, 99, 93, 9, 93, 13, 30, 62, 5, 21, 21, 6, 81, 67, 4, 10, 17, 84, 83, 62, 26, 7, 3, 84, 78, 88, 12, 83, 87, 14, 31, 27, 9, 93, 36, 79, 53, 12, 64, 84, 84, 72, 22, 81, 72, 22, 79, 63, 34, 73, 28, 1, 29, 44, 39, 72, 0, 60, 37, 93, 0, 20, 68, 51, 10, 21, 29, 16, 84, 63, 30, 50, 59, 22, 10, 65, 92, 13, 89, 90, 46, 33, 7, 72, 70, 19, 44, 17, 88, 45, 78, 90, 41, 19, 41, 36, 96, 85, 60, 29, 59, 40, 37, 6, 38, 54, 54, 93, 98, 76, 13, 91, 53, 31, 82, 27, 18, 26, 69, 8, 100, 81, 90, 13, 78, 22, 52, 16, 89, 38, 38, 52, 38, 5, 17, 27, 35, 98, 50, 87, 81, 47, 90, 11, 20, 81, 57, 81, 68, 78, 91, 70, 1, 35, 100, 91, 33, 91, 23, 57, 36, 51, 24, 36, 2, 52, 98, 89, 35, 63, 87, 28, 98, 89, 58, 58, 13, 53, 48, 35, 10, 86, 33, 13, 86, 47, 43, 62, 16, 51, 98, 6, 17, 60, 24, 86, 42, 84, 96, 78, 56, 20, 88, 30, 87, 97, 64, 41, 100, 57, 59, 17, 78, 49, 81, 22, 86, 25, 33, 52, 19, 76, 36, 49, 25, 42, 23, 83, 99, 8, 61, 9, 28, 88, 27, 24, 57, 26, 41, 30, 8, 7, 33, 53, 13, 20, 28, 88, 72, 29, 4, 59, 42, 19, 48, 58, 59, 31, 49, 99, 20, 44, 29, 29, 34, 67, 65, 16, 21, 55, 89, 12, 22, 6, 54, 25, 51, 41, 59, 85, 14, 24, 10, 15, 91, 29, 3, 10, 9, 24, 22, 44, 4, 20, 97, 37, 58, 83, 50, 5, 71, 49, 70, 93, 99, 73, 17, 95, 63, 15, 61, 54, 60, 85, 6, 35, 14, 29, 16, 41, 33, 95, 47, 94, 36, 30, 30, 7, 96, 50, 77, 26, 19, 16, 61, 2, 59, 61, 53, 20, 28, 67, 39, 42, 60, 13, 46, 95, 60, 83, 79, 64, 76, 44, 69, 99, 45, 5, 35, 95, 25, 25, 93, 46, 87, 6, 3, 56, 77, 22, 77, 39, 89, 54, 44, 66, 86, 83, 29, 92, 74, 19, 31, 45, 14, 48, 53, 27, 11, 29, 35, 84, 18, 82, 62, 88, 78, 77, 26, 70, 41, 23, 73, 1, 44, 25, 87, 92, 6, 43, 92, 8, 29, 77, 91, 13, 5, 33, 73, 26, 83, 61, 99, 29, 83, 23, 30, 31, 87, 86, 50, 62, 84, 79, 13, 36, 95, 60, 72, 95, 36, 20, 57, 22, 61, 3, 15, 98, 32, 3, 35, 71, 7, 9, 10, 35, 16, 93, 31, 6, 55, 98, 20, 97, 61, 78, 84, 37, 3, 98, 0, 37, 9, 68, 86, 23, 37, 46, 12, 39, 28, 31, 56, 48, 89, 27, 39, 90, 60, 26, 36, 23, 81, 55, 89, 71, 19, 90, 63, 67, 33, 1, 95, 68, 70, 23, 11, 19, 47, 20, 66, 15, 55, 98, 45, 79, 66, 46, 80, 36, 53, 68, 49, 66, 34, 36, 32, 71, 71, 66, 31, 58, 53, 41, 33, 52, 41, 37, 61, 39, 42, 24, 25, 7, 85, 21, 40, 100, 54, 49, 66, 63, 86, 17, 5, 94, 96, 79, 81, 19, 85, 7, 52, 52, 91, 49, 1, 18, 10, 82, 68, 94, 10, 67, 6, 24, 19, 77, 83, 2, 36, 88, 38, 43, 32, 65, 39, 8, 30, 56, 50, 75, 71, 50, 77, 26]\n",
      "10 : 15\n",
      "81 : 14\n",
      "59 : 16\n",
      "88 : 14\n",
      "20 : 14\n",
      "33 : 17\n",
      "45 : 9\n",
      "21 : 11\n",
      "38 : 10\n",
      "85 : 11\n",
      "80 : 7\n",
      "35 : 14\n",
      "10 : 15\n",
      "14 : 12\n",
      "51 : 10\n",
      "37 : 14\n",
      "16 : 11\n",
      "39 : 11\n",
      "65 : 10\n",
      "95 : 10\n",
      "4 : 7\n",
      "14 : 12\n",
      "51 : 10\n",
      "68 : 8\n",
      "73 : 8\n",
      "42 : 9\n",
      "33 : 17\n",
      "17 : 12\n",
      "55 : 7\n",
      "38 : 10\n",
      "96 : 14\n",
      "66 : 8\n",
      "52 : 11\n",
      "35 : 14\n",
      "23 : 13\n",
      "61 : 9\n",
      "32 : 7\n",
      "81 : 14\n",
      "46 : 14\n",
      "33 : 17\n",
      "58 : 7\n",
      "51 : 10\n",
      "31 : 10\n",
      "47 : 8\n",
      "71 : 12\n",
      "35 : 14\n",
      "23 : 13\n",
      "8 : 11\n",
      "59 : 16\n",
      "5 : 10\n",
      "1 : 8\n",
      "94 : 6\n",
      "62 : 8\n",
      "36 : 16\n",
      "97 : 7\n",
      "81 : 14\n",
      "96 : 14\n",
      "4 : 7\n",
      "20 : 14\n",
      "17 : 12\n",
      "94 : 6\n",
      "62 : 8\n",
      "54 : 12\n",
      "70 : 10\n",
      "62 : 8\n",
      "20 : 14\n",
      "8 : 11\n",
      "8 : 11\n",
      "85 : 11\n",
      "95 : 10\n",
      "33 : 17\n",
      "44 : 10\n",
      "76 : 4\n",
      "67 : 9\n",
      "34 : 7\n",
      "83 : 18\n",
      "65 : 10\n",
      "79 : 9\n",
      "30 : 15\n",
      "75 : 5\n",
      "99 : 12\n",
      "57 : 7\n",
      "96 : 14\n",
      "16 : 11\n",
      "30 : 15\n",
      "47 : 8\n",
      "39 : 11\n",
      "77 : 13\n",
      "97 : 7\n",
      "0 : 6\n",
      "54 : 12\n",
      "25 : 11\n",
      "8 : 11\n",
      "21 : 11\n",
      "74 : 3\n",
      "38 : 10\n",
      "16 : 11\n",
      "6 : 16\n",
      "6 : 16\n",
      "60 : 15\n",
      "71 : 12\n",
      "60 : 15\n",
      "23 : 13\n",
      "25 : 11\n",
      "32 : 7\n",
      "55 : 7\n",
      "60 : 15\n",
      "100 : 8\n",
      "1 : 8\n",
      "71 : 12\n",
      "6 : 16\n",
      "55 : 7\n",
      "42 : 9\n",
      "3 : 8\n",
      "84 : 11\n",
      "6 : 16\n",
      "71 : 12\n",
      "45 : 9\n",
      "9 : 8\n",
      "17 : 12\n",
      "35 : 14\n",
      "70 : 10\n",
      "56 : 7\n",
      "96 : 14\n",
      "42 : 9\n",
      "82 : 6\n",
      "83 : 18\n",
      "2 : 4\n",
      "23 : 13\n",
      "50 : 13\n",
      "18 : 6\n",
      "63 : 9\n",
      "100 : 8\n",
      "87 : 11\n",
      "73 : 8\n",
      "54 : 12\n",
      "80 : 7\n",
      "17 : 12\n",
      "29 : 14\n",
      "14 : 12\n",
      "77 : 13\n",
      "30 : 15\n",
      "33 : 17\n",
      "46 : 14\n",
      "43 : 6\n",
      "88 : 14\n",
      "40 : 8\n",
      "96 : 14\n",
      "8 : 11\n",
      "80 : 7\n",
      "69 : 5\n",
      "73 : 8\n",
      "56 : 7\n",
      "50 : 13\n",
      "100 : 8\n",
      "10 : 15\n",
      "27 : 9\n",
      "30 : 15\n",
      "45 : 9\n",
      "99 : 12\n",
      "21 : 11\n",
      "60 : 15\n",
      "60 : 15\n",
      "28 : 10\n",
      "31 : 10\n",
      "5 : 10\n",
      "37 : 14\n",
      "46 : 14\n",
      "39 : 11\n",
      "71 : 12\n",
      "30 : 15\n",
      "88 : 14\n",
      "87 : 11\n",
      "46 : 14\n",
      "52 : 11\n",
      "12 : 6\n",
      "87 : 11\n",
      "49 : 11\n",
      "18 : 6\n",
      "88 : 14\n",
      "83 : 18\n",
      "82 : 6\n",
      "65 : 10\n",
      "42 : 9\n",
      "65 : 10\n",
      "14 : 12\n",
      "48 : 6\n",
      "54 : 12\n",
      "43 : 6\n",
      "41 : 11\n",
      "40 : 8\n",
      "93 : 11\n",
      "84 : 11\n",
      "10 : 15\n",
      "21 : 11\n",
      "60 : 15\n",
      "52 : 11\n",
      "41 : 11\n",
      "99 : 12\n",
      "16 : 11\n",
      "22 : 13\n",
      "26 : 9\n",
      "12 : 6\n",
      "72 : 11\n",
      "96 : 14\n",
      "46 : 14\n",
      "59 : 16\n",
      "89 : 10\n",
      "7 : 11\n",
      "45 : 9\n",
      "80 : 7\n",
      "50 : 13\n",
      "90 : 9\n",
      "60 : 15\n",
      "21 : 11\n",
      "30 : 15\n",
      "28 : 10\n",
      "50 : 13\n",
      "36 : 16\n",
      "85 : 11\n",
      "32 : 7\n",
      "80 : 7\n",
      "63 : 9\n",
      "43 : 6\n",
      "46 : 14\n",
      "29 : 14\n",
      "73 : 8\n",
      "64 : 4\n",
      "59 : 16\n",
      "49 : 11\n",
      "78 : 13\n",
      "14 : 12\n",
      "51 : 10\n",
      "79 : 9\n",
      "88 : 14\n",
      "25 : 11\n",
      "56 : 7\n",
      "72 : 11\n",
      "37 : 14\n",
      "20 : 14\n",
      "13 : 14\n",
      "95 : 10\n",
      "13 : 14\n",
      "81 : 14\n",
      "94 : 6\n",
      "97 : 7\n",
      "59 : 16\n",
      "75 : 5\n",
      "57 : 7\n",
      "91 : 10\n",
      "6 : 16\n",
      "83 : 18\n",
      "9 : 8\n",
      "5 : 10\n",
      "28 : 10\n",
      "91 : 10\n",
      "19 : 12\n",
      "10 : 15\n",
      "99 : 12\n",
      "85 : 11\n",
      "51 : 10\n",
      "37 : 14\n",
      "24 : 9\n",
      "11 : 5\n",
      "88 : 14\n",
      "83 : 18\n",
      "47 : 8\n",
      "46 : 14\n",
      "14 : 12\n",
      "65 : 10\n",
      "54 : 12\n",
      "23 : 13\n",
      "49 : 11\n",
      "52 : 11\n",
      "70 : 10\n",
      "75 : 5\n",
      "74 : 3\n",
      "3 : 8\n",
      "50 : 13\n",
      "34 : 7\n",
      "65 : 10\n",
      "40 : 8\n",
      "83 : 18\n",
      "90 : 9\n",
      "92 : 7\n",
      "77 : 13\n",
      "97 : 7\n",
      "78 : 13\n",
      "15 : 7\n",
      "0 : 6\n",
      "28 : 10\n",
      "10 : 15\n",
      "83 : 18\n",
      "72 : 11\n",
      "96 : 14\n",
      "69 : 5\n",
      "15 : 7\n",
      "78 : 13\n",
      "65 : 10\n",
      "37 : 14\n",
      "23 : 13\n",
      "66 : 8\n",
      "33 : 17\n",
      "99 : 12\n",
      "58 : 7\n",
      "98 : 10\n",
      "17 : 12\n",
      "96 : 14\n",
      "19 : 12\n",
      "93 : 11\n",
      "7 : 11\n",
      "32 : 7\n",
      "33 : 17\n",
      "90 : 9\n",
      "92 : 7\n",
      "5 : 10\n",
      "34 : 7\n",
      "11 : 5\n",
      "89 : 10\n",
      "22 : 13\n",
      "45 : 9\n",
      "80 : 7\n",
      "6 : 16\n",
      "18 : 6\n",
      "100 : 8\n",
      "7 : 11\n",
      "99 : 12\n",
      "13 : 14\n",
      "37 : 14\n",
      "82 : 6\n",
      "77 : 13\n",
      "70 : 10\n",
      "22 : 13\n",
      "72 : 11\n",
      "88 : 14\n",
      "67 : 9\n",
      "83 : 18\n",
      "14 : 12\n",
      "72 : 11\n",
      "36 : 16\n",
      "78 : 13\n",
      "14 : 12\n",
      "67 : 9\n",
      "47 : 8\n",
      "27 : 9\n",
      "78 : 13\n",
      "46 : 14\n",
      "8 : 11\n",
      "27 : 9\n",
      "77 : 13\n",
      "85 : 11\n",
      "71 : 12\n",
      "96 : 14\n",
      "38 : 10\n",
      "35 : 14\n",
      "44 : 10\n",
      "63 : 9\n",
      "96 : 14\n",
      "54 : 12\n",
      "4 : 7\n",
      "13 : 14\n",
      "75 : 5\n",
      "0 : 6\n",
      "40 : 8\n",
      "91 : 10\n",
      "37 : 14\n",
      "36 : 16\n",
      "38 : 10\n",
      "59 : 16\n",
      "24 : 9\n",
      "69 : 5\n",
      "59 : 16\n",
      "59 : 16\n",
      "4 : 7\n",
      "77 : 13\n",
      "15 : 7\n",
      "85 : 11\n",
      "59 : 16\n",
      "49 : 11\n",
      "40 : 8\n",
      "93 : 11\n",
      "70 : 10\n",
      "30 : 15\n",
      "44 : 10\n",
      "48 : 6\n",
      "33 : 17\n",
      "6 : 16\n",
      "40 : 8\n",
      "34 : 7\n",
      "7 : 11\n",
      "25 : 11\n",
      "46 : 14\n",
      "68 : 8\n",
      "79 : 9\n",
      "51 : 10\n",
      "50 : 13\n",
      "22 : 13\n",
      "81 : 14\n",
      "39 : 11\n",
      "87 : 11\n",
      "1 : 8\n",
      "92 : 7\n",
      "21 : 11\n",
      "83 : 18\n",
      "67 : 9\n",
      "99 : 12\n",
      "93 : 11\n",
      "9 : 8\n",
      "93 : 11\n",
      "13 : 14\n",
      "30 : 15\n",
      "62 : 8\n",
      "5 : 10\n",
      "21 : 11\n",
      "21 : 11\n",
      "6 : 16\n",
      "81 : 14\n",
      "67 : 9\n",
      "4 : 7\n",
      "10 : 15\n",
      "17 : 12\n",
      "84 : 11\n",
      "83 : 18\n",
      "62 : 8\n",
      "26 : 9\n",
      "7 : 11\n",
      "3 : 8\n",
      "84 : 11\n",
      "78 : 13\n",
      "88 : 14\n",
      "12 : 6\n",
      "83 : 18\n",
      "87 : 11\n",
      "14 : 12\n",
      "31 : 10\n",
      "27 : 9\n",
      "9 : 8\n",
      "93 : 11\n",
      "36 : 16\n",
      "79 : 9\n",
      "53 : 8\n",
      "12 : 6\n",
      "64 : 4\n",
      "84 : 11\n",
      "84 : 11\n",
      "72 : 11\n",
      "22 : 13\n",
      "81 : 14\n",
      "72 : 11\n",
      "22 : 13\n",
      "79 : 9\n",
      "63 : 9\n",
      "34 : 7\n",
      "73 : 8\n",
      "28 : 10\n",
      "1 : 8\n",
      "29 : 14\n",
      "44 : 10\n",
      "39 : 11\n",
      "72 : 11\n",
      "0 : 6\n",
      "60 : 15\n",
      "37 : 14\n",
      "93 : 11\n",
      "0 : 6\n",
      "20 : 14\n",
      "68 : 8\n",
      "51 : 10\n",
      "10 : 15\n",
      "21 : 11\n",
      "29 : 14\n",
      "16 : 11\n",
      "84 : 11\n",
      "63 : 9\n",
      "30 : 15\n",
      "50 : 13\n",
      "59 : 16\n",
      "22 : 13\n",
      "10 : 15\n",
      "65 : 10\n",
      "92 : 7\n",
      "13 : 14\n",
      "89 : 10\n",
      "90 : 9\n",
      "46 : 14\n",
      "33 : 17\n",
      "7 : 11\n",
      "72 : 11\n",
      "70 : 10\n",
      "19 : 12\n",
      "44 : 10\n",
      "17 : 12\n",
      "88 : 14\n",
      "45 : 9\n",
      "78 : 13\n",
      "90 : 9\n",
      "41 : 11\n",
      "19 : 12\n",
      "41 : 11\n",
      "36 : 16\n",
      "96 : 14\n",
      "85 : 11\n",
      "60 : 15\n",
      "29 : 14\n",
      "59 : 16\n",
      "40 : 8\n",
      "37 : 14\n",
      "6 : 16\n",
      "38 : 10\n",
      "54 : 12\n",
      "54 : 12\n",
      "93 : 11\n",
      "98 : 10\n",
      "76 : 4\n",
      "13 : 14\n",
      "91 : 10\n",
      "53 : 8\n",
      "31 : 10\n",
      "82 : 6\n",
      "27 : 9\n",
      "18 : 6\n",
      "26 : 9\n",
      "69 : 5\n",
      "8 : 11\n",
      "100 : 8\n",
      "81 : 14\n",
      "90 : 9\n",
      "13 : 14\n",
      "78 : 13\n",
      "22 : 13\n",
      "52 : 11\n",
      "16 : 11\n",
      "89 : 10\n",
      "38 : 10\n",
      "38 : 10\n",
      "52 : 11\n",
      "38 : 10\n",
      "5 : 10\n",
      "17 : 12\n",
      "27 : 9\n",
      "35 : 14\n",
      "98 : 10\n",
      "50 : 13\n",
      "87 : 11\n",
      "81 : 14\n",
      "47 : 8\n",
      "90 : 9\n",
      "11 : 5\n",
      "20 : 14\n",
      "81 : 14\n",
      "57 : 7\n",
      "81 : 14\n",
      "68 : 8\n",
      "78 : 13\n",
      "91 : 10\n",
      "70 : 10\n",
      "1 : 8\n",
      "35 : 14\n",
      "100 : 8\n",
      "91 : 10\n",
      "33 : 17\n",
      "91 : 10\n",
      "23 : 13\n",
      "57 : 7\n",
      "36 : 16\n",
      "51 : 10\n",
      "24 : 9\n",
      "36 : 16\n",
      "2 : 4\n",
      "52 : 11\n",
      "98 : 10\n",
      "89 : 10\n",
      "35 : 14\n",
      "63 : 9\n",
      "87 : 11\n",
      "28 : 10\n",
      "98 : 10\n",
      "89 : 10\n",
      "58 : 7\n",
      "58 : 7\n",
      "13 : 14\n",
      "53 : 8\n",
      "48 : 6\n",
      "35 : 14\n",
      "10 : 15\n",
      "86 : 8\n",
      "33 : 17\n",
      "13 : 14\n",
      "86 : 8\n",
      "47 : 8\n",
      "43 : 6\n",
      "62 : 8\n",
      "16 : 11\n",
      "51 : 10\n",
      "98 : 10\n",
      "6 : 16\n",
      "17 : 12\n",
      "60 : 15\n",
      "24 : 9\n",
      "86 : 8\n",
      "42 : 9\n",
      "84 : 11\n",
      "96 : 14\n",
      "78 : 13\n",
      "56 : 7\n",
      "20 : 14\n",
      "88 : 14\n",
      "30 : 15\n",
      "87 : 11\n",
      "97 : 7\n",
      "64 : 4\n",
      "41 : 11\n",
      "100 : 8\n",
      "57 : 7\n",
      "59 : 16\n",
      "17 : 12\n",
      "78 : 13\n",
      "49 : 11\n",
      "81 : 14\n",
      "22 : 13\n",
      "86 : 8\n",
      "25 : 11\n",
      "33 : 17\n",
      "52 : 11\n",
      "19 : 12\n",
      "76 : 4\n",
      "36 : 16\n",
      "49 : 11\n",
      "25 : 11\n",
      "42 : 9\n",
      "23 : 13\n",
      "83 : 18\n",
      "99 : 12\n",
      "8 : 11\n",
      "61 : 9\n",
      "9 : 8\n",
      "28 : 10\n",
      "88 : 14\n",
      "27 : 9\n",
      "24 : 9\n",
      "57 : 7\n",
      "26 : 9\n",
      "41 : 11\n",
      "30 : 15\n",
      "8 : 11\n",
      "7 : 11\n",
      "33 : 17\n",
      "53 : 8\n",
      "13 : 14\n",
      "20 : 14\n",
      "28 : 10\n",
      "88 : 14\n",
      "72 : 11\n",
      "29 : 14\n",
      "4 : 7\n",
      "59 : 16\n",
      "42 : 9\n",
      "19 : 12\n",
      "48 : 6\n",
      "58 : 7\n",
      "59 : 16\n",
      "31 : 10\n",
      "49 : 11\n",
      "99 : 12\n",
      "20 : 14\n",
      "44 : 10\n",
      "29 : 14\n",
      "29 : 14\n",
      "34 : 7\n",
      "67 : 9\n",
      "65 : 10\n",
      "16 : 11\n",
      "21 : 11\n",
      "55 : 7\n",
      "89 : 10\n",
      "12 : 6\n",
      "22 : 13\n",
      "6 : 16\n",
      "54 : 12\n",
      "25 : 11\n",
      "51 : 10\n",
      "41 : 11\n",
      "59 : 16\n",
      "85 : 11\n",
      "14 : 12\n",
      "24 : 9\n",
      "10 : 15\n",
      "15 : 7\n",
      "91 : 10\n",
      "29 : 14\n",
      "3 : 8\n",
      "10 : 15\n",
      "9 : 8\n",
      "24 : 9\n",
      "22 : 13\n",
      "44 : 10\n",
      "4 : 7\n",
      "20 : 14\n",
      "97 : 7\n",
      "37 : 14\n",
      "58 : 7\n",
      "83 : 18\n",
      "50 : 13\n",
      "5 : 10\n",
      "71 : 12\n",
      "49 : 11\n",
      "70 : 10\n",
      "93 : 11\n",
      "99 : 12\n",
      "73 : 8\n",
      "17 : 12\n",
      "95 : 10\n",
      "63 : 9\n",
      "15 : 7\n",
      "61 : 9\n",
      "54 : 12\n",
      "60 : 15\n",
      "85 : 11\n",
      "6 : 16\n",
      "35 : 14\n",
      "14 : 12\n",
      "29 : 14\n",
      "16 : 11\n",
      "41 : 11\n",
      "33 : 17\n",
      "95 : 10\n",
      "47 : 8\n",
      "94 : 6\n",
      "36 : 16\n",
      "30 : 15\n",
      "30 : 15\n",
      "7 : 11\n",
      "96 : 14\n",
      "50 : 13\n",
      "77 : 13\n",
      "26 : 9\n",
      "19 : 12\n",
      "16 : 11\n",
      "61 : 9\n",
      "2 : 4\n",
      "59 : 16\n",
      "61 : 9\n",
      "53 : 8\n",
      "20 : 14\n",
      "28 : 10\n",
      "67 : 9\n",
      "39 : 11\n",
      "42 : 9\n",
      "60 : 15\n",
      "13 : 14\n",
      "46 : 14\n",
      "95 : 10\n",
      "60 : 15\n",
      "83 : 18\n",
      "79 : 9\n",
      "64 : 4\n",
      "76 : 4\n",
      "44 : 10\n",
      "69 : 5\n",
      "99 : 12\n",
      "45 : 9\n",
      "5 : 10\n",
      "35 : 14\n",
      "95 : 10\n",
      "25 : 11\n",
      "25 : 11\n",
      "93 : 11\n",
      "46 : 14\n",
      "87 : 11\n",
      "6 : 16\n",
      "3 : 8\n",
      "56 : 7\n",
      "77 : 13\n",
      "22 : 13\n",
      "77 : 13\n",
      "39 : 11\n",
      "89 : 10\n",
      "54 : 12\n",
      "44 : 10\n",
      "66 : 8\n",
      "86 : 8\n",
      "83 : 18\n",
      "29 : 14\n",
      "92 : 7\n",
      "74 : 3\n",
      "19 : 12\n",
      "31 : 10\n",
      "45 : 9\n",
      "14 : 12\n",
      "48 : 6\n",
      "53 : 8\n",
      "27 : 9\n",
      "11 : 5\n",
      "29 : 14\n",
      "35 : 14\n",
      "84 : 11\n",
      "18 : 6\n",
      "82 : 6\n",
      "62 : 8\n",
      "88 : 14\n",
      "78 : 13\n",
      "77 : 13\n",
      "26 : 9\n",
      "70 : 10\n",
      "41 : 11\n",
      "23 : 13\n",
      "73 : 8\n",
      "1 : 8\n",
      "44 : 10\n",
      "25 : 11\n",
      "87 : 11\n",
      "92 : 7\n",
      "6 : 16\n",
      "43 : 6\n",
      "92 : 7\n",
      "8 : 11\n",
      "29 : 14\n",
      "77 : 13\n",
      "91 : 10\n",
      "13 : 14\n",
      "5 : 10\n",
      "33 : 17\n",
      "73 : 8\n",
      "26 : 9\n",
      "83 : 18\n",
      "61 : 9\n",
      "99 : 12\n",
      "29 : 14\n",
      "83 : 18\n",
      "23 : 13\n",
      "30 : 15\n",
      "31 : 10\n",
      "87 : 11\n",
      "86 : 8\n",
      "50 : 13\n",
      "62 : 8\n",
      "84 : 11\n",
      "79 : 9\n",
      "13 : 14\n",
      "36 : 16\n",
      "95 : 10\n",
      "60 : 15\n",
      "72 : 11\n",
      "95 : 10\n",
      "36 : 16\n",
      "20 : 14\n",
      "57 : 7\n",
      "22 : 13\n",
      "61 : 9\n",
      "3 : 8\n",
      "15 : 7\n",
      "98 : 10\n",
      "32 : 7\n",
      "3 : 8\n",
      "35 : 14\n",
      "71 : 12\n",
      "7 : 11\n",
      "9 : 8\n",
      "10 : 15\n",
      "35 : 14\n",
      "16 : 11\n",
      "93 : 11\n",
      "31 : 10\n",
      "6 : 16\n",
      "55 : 7\n",
      "98 : 10\n",
      "20 : 14\n",
      "97 : 7\n",
      "61 : 9\n",
      "78 : 13\n",
      "84 : 11\n",
      "37 : 14\n",
      "3 : 8\n",
      "98 : 10\n",
      "0 : 6\n",
      "37 : 14\n",
      "9 : 8\n",
      "68 : 8\n",
      "86 : 8\n",
      "23 : 13\n",
      "37 : 14\n",
      "46 : 14\n",
      "12 : 6\n",
      "39 : 11\n",
      "28 : 10\n",
      "31 : 10\n",
      "56 : 7\n",
      "48 : 6\n",
      "89 : 10\n",
      "27 : 9\n",
      "39 : 11\n",
      "90 : 9\n",
      "60 : 15\n",
      "26 : 9\n",
      "36 : 16\n",
      "23 : 13\n",
      "81 : 14\n",
      "55 : 7\n",
      "89 : 10\n",
      "71 : 12\n",
      "19 : 12\n",
      "90 : 9\n",
      "63 : 9\n",
      "67 : 9\n",
      "33 : 17\n",
      "1 : 8\n",
      "95 : 10\n",
      "68 : 8\n",
      "70 : 10\n",
      "23 : 13\n",
      "11 : 5\n",
      "19 : 12\n",
      "47 : 8\n",
      "20 : 14\n",
      "66 : 8\n",
      "15 : 7\n",
      "55 : 7\n",
      "98 : 10\n",
      "45 : 9\n",
      "79 : 9\n",
      "66 : 8\n",
      "46 : 14\n",
      "80 : 7\n",
      "36 : 16\n",
      "53 : 8\n",
      "68 : 8\n",
      "49 : 11\n",
      "66 : 8\n",
      "34 : 7\n",
      "36 : 16\n",
      "32 : 7\n",
      "71 : 12\n",
      "71 : 12\n",
      "66 : 8\n",
      "31 : 10\n",
      "58 : 7\n",
      "53 : 8\n",
      "41 : 11\n",
      "33 : 17\n",
      "52 : 11\n",
      "41 : 11\n",
      "37 : 14\n",
      "61 : 9\n",
      "39 : 11\n",
      "42 : 9\n",
      "24 : 9\n",
      "25 : 11\n",
      "7 : 11\n",
      "85 : 11\n",
      "21 : 11\n",
      "40 : 8\n",
      "100 : 8\n",
      "54 : 12\n",
      "49 : 11\n",
      "66 : 8\n",
      "63 : 9\n",
      "86 : 8\n",
      "17 : 12\n",
      "5 : 10\n",
      "94 : 6\n",
      "96 : 14\n",
      "79 : 9\n",
      "81 : 14\n",
      "19 : 12\n",
      "85 : 11\n",
      "7 : 11\n",
      "52 : 11\n",
      "52 : 11\n",
      "91 : 10\n",
      "49 : 11\n",
      "1 : 8\n",
      "18 : 6\n",
      "10 : 15\n",
      "82 : 6\n",
      "68 : 8\n",
      "94 : 6\n",
      "10 : 15\n",
      "67 : 9\n",
      "6 : 16\n",
      "24 : 9\n",
      "19 : 12\n",
      "77 : 13\n",
      "83 : 18\n",
      "2 : 4\n",
      "36 : 16\n",
      "88 : 14\n",
      "38 : 10\n",
      "43 : 6\n",
      "32 : 7\n",
      "65 : 10\n",
      "39 : 11\n",
      "8 : 11\n",
      "30 : 15\n",
      "56 : 7\n",
      "50 : 13\n",
      "75 : 5\n",
      "71 : 12\n",
      "50 : 13\n",
      "77 : 13\n",
      "26 : 9\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "x = [random.randint(0,100)for i in range(1000)]\n",
    "print(x)\n",
    "for i in x:\n",
    "    print(i,':',x.count(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "输入下标上限2\n",
      "输入下标下限10\n",
      "输入一个列表zhang,jia ,hao\n",
      "['hang', 'jia ', 'ha']\n",
      "['ha']\n"
     ]
    }
   ],
   "source": [
    "x = int(input(\"输入下标上限\"))\n",
    "y = int(input(\"输入下标下限\"))\n",
    "z = input(\"输入一个列表\")\n",
    "c=z[1:-1].split(\",\")\n",
    "print(c)\n",
    "print(c[x:y+1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "您输入的键不存在\n"
     ]
    }
   ],
   "source": [
    "print(d.get(a,'您输入的键不存在'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[74, 69, 70, 44, 98, 5, 40, 33, 9, 100, 27, 50, 18, 92, 62, 19, 99, 32, 58, 82]"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import random\n",
    "s = [random.randint(0,100)for i in range(20)]\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5, 9, 33, 40, 44, 69, 70, 74, 98, 100, 99, 92, 82, 62, 58, 50, 32, 27, 19, 18]\n"
     ]
    }
   ],
   "source": [
    "a = sorted(s[:10])\n",
    "b = sorted(s[10:],reverse = True)\n",
    "x = a+b\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "165px"
   },
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
